Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Name = "AddressControl"
Me.Size = New System.Drawing.Size(392, 200)
Me.ResumeLayout(False)
End Sub
#End Region
Dim WithEvents m_Address As New Address()
<TypeConverter(GetType(AddressTypeConverter))> _
Property Address() As Address
Get
Return m_Address
End Get
Set(ByVal Value As Address)
m_Address = Value
RefreshControls()
End Set
End Property
' Refresh controls when any property changes
Private Sub Address_PropertyChanged(ByVal propertyName As String) Handles m_Address.PropertyChanged
RefreshControls()
End Sub
' Display Address properties in the control's fields.
Private Sub RefreshControls()
txtStreet.Text = m_Address.Street
txtCity.Text = m_Address.City
txtZip.Text = m_Address.Zip
txtState.Text = m_Address.State
txtCountry.Text = m_Address.Country
End Sub
'---------------------------------------------
' The TypeConverter for the Address property
'---------------------------------------------
Public Class AddressTypeConverter
Inherits TypeConverter
Public Overloads Overrides Function GetProperties(ByVal context As System.ComponentModel.ITypeDescriptorContext, ByVal value As Object, ByVal attributes() As System.Attribute) As System.ComponentModel.PropertyDescriptorCollection
Public Overloads Overrides Function GetPropertiesSupported(ByVal context As System.ComponentModel.ITypeDescriptorContext) As Boolean
Return True
End Function
End Class
End Class
'---------------------------------------------
' The class that holds Address info
'---------------------------------------------
Public Class Address
Event PropertyChanged(ByVal propertyName As String)
' private members
Dim m_Street As String
Dim m_City As String
Dim m_Zip As String
Dim m_State As String
Dim m_Country As String
Property Street() As String
Get
Return m_Street
End Get
Set(ByVal Value As String)
If m_Street <> Value Then
m_Street = Value
RaiseEvent PropertyChanged("Street")
End If
End Set
End Property
Property City() As String
Get
Return m_City
End Get
Set(ByVal Value As String)
If m_City <> Value Then
m_City = Value
RaiseEvent PropertyChanged("City")
End If
End Set
End Property
Property Zip() As String
Get
Return m_Zip
End Get
Set(ByVal Value As String)
If m_Zip <> Value Then
m_Zip = Value
RaiseEvent PropertyChanged("Zip")
End If
End Set
End Property
Property State() As String
Get
Return m_State
End Get
Set(ByVal Value As String)
If m_State <> Value Then
m_State = Value
RaiseEvent PropertyChanged("State")
End If
End Set
End Property
Property Country() As String
Get
Return m_Country
End Get
Set(ByVal Value As String)
If m_Country <> Value Then
m_Country = Value
RaiseEvent PropertyChanged("Country")
End If
End Set
End Property
' override ToString
Overrides Function ToString() As String
Return "(Address)"
End Function
End Class
' custom license provider class
Class LicWindowsFileLicenseProvider
Inherits LicenseProvider
Public Overrides Function GetLicense(ByVal context As LicenseContext, ByVal typ As System.Type, ByVal instance As Object, ByVal allowExceptions As Boolean) As License
' This is the name of the control.
Dim ctrlName As String = typ.FullName
If context.UsageMode = LicenseUsageMode.Designtime Then
' We are at design mode: check that there is a .lic file in Windows system directory.
' Build the full path of the .lic file.
Dim filename As String = Environment.SystemDirectory() & "\" & ctrlName & ".lic"
Dim fs As System.IO.StreamReader
' open the .lic file
Try
' Open the license file, exception if not found.
fs = New System.IO.StreamReader(filename)
' Read its contents.
Dim licText As String = fs.ReadToEnd
' Compare with the expected license text.
If licText <> ctrlName & " is a licensed component." Then
' Any exception type will do.
Throw New ArgumentException()
End If
Catch ex As Exception
' Any error throws a LicenseException object, if possible
' else it just returns Nothing.
If allowExceptions Then
Throw New LicenseException(typ, instance, "Can't find design-time license for " & ctrlName)
Else
Return Nothing
End If
Finally
' In all cases, close the StreamReader if open.
If Not (fs Is Nothing) Then fs.Close()
End Try
' If we get here, we can return a RuntimeLicense object.
Return New DesignTimeLicense(Me, typ)
Else
' We enforce no licensing at runtime, so we always return a RunTimeLicense.
Return New RuntimeLicense(Me, typ)
End If
End Function
' Nested class for design-time license.
Public Class DesignTimeLicense
Inherits License
Private owner As LicWindowsFileLicenseProvider
Private typ As Type
' The constructor for this class.
Sub New(ByVal owner As LicWindowsFileLicenseProvider, ByVal typ As Type)
Me.owner = owner
Me.typ = typ
End Sub
Overrides ReadOnly Property LicenseKey() As String
Get
' Just return the type name in this demo.
Return typ.FullName
End Get
End Property
Overrides Sub Dispose()
' There is nothing to do here.
End Sub
End Class
' Nested class for run-time license.
Public Class RuntimeLicense
Inherits License
Private owner As LicWindowsFileLicenseProvider
Private typ As Type
' The constructor for this class.
Sub New(ByVal owner As LicWindowsFileLicenseProvider, ByVal typ As Type)
Me.owner = owner
Me.typ = typ
End Sub
Overrides ReadOnly Property LicenseKey() As String